#include <iostream>
#include <stdio.h>

using namespace std;

struct Node
{
    int data;
    Node *next;
};

int main()
{
    Node* head = new Node;
    Node* tail = head;

    int n, q, k;
    cin >> n;
    cin >> q;
    for (int i = 0; i < n; i++)
    {
        Node* p = new Node;
        cin >> p->data;
        p->next = NULL;
        tail->next = p;
        tail = p;
    }

    for (int i = 0; i < q; i++)
    {
        Node* p;
        k = 0;
        cin >> k;
        for (p = head->next ; p->data != k ;p = p->next)
        {
            cout << p->data << " ";
            
        }
        cout << k;
        cout << endl;
    }

    return 0;
}